<template>
  <el-tree :props="props" :load="loadNode" lazy @node-click="handle">
  </el-tree>
</template>

<script>
import { selectItemCategoryByParentId } from '@/api/home.js'
export default {
  data() {
    return {
      props: {
        label: 'name',
        children: 'zones',
        isLeaf: 'leaf'
      },
      treeData: []
    };
  },
  methods: {
    handle(data){
      this.$emit('sendTreeData',data)
    },
    loadNode(node, resolve) {
      if (node.level === 0) {
        this.selectItemCategoryByParentId()
        return resolve(this.treeData);
      }
      if (node.level > 1) {
        this.selectItemCategoryByParentId()
        return resolve([]);
      }

    },
    async selectItemCategoryByParentId(type) {
      let res = await selectItemCategoryByParentId({ type })
      if (res.data.status == 200) {
        this.treeData = res.data.result
      }
    }
  },
  created() {
    this.selectItemCategoryByParentId()
  }
};
</script>

<style>
</style>